class ReviewsController < ApplicationController
  filter_access_to :all
  layout 'slim'

  def new
    @review = Review.new

  end

  def create
    @review = Review.new(params[:review])
    @review.reviewable_id = params[:review][:reviewable_id]
    @review.reviewable_type = params[:review][:reviewable_type]
    @review.user_id = current_user.id
   
    if @review.save
      flash[:notice] = "Review created"
      redirect_to_request_uri
    else
      render :new
    end
  end

  def edit
    @review = Review.find(params[:id])
  end

  def update
    @review = Review.find(params[:id])

    if @review.update_attributes(params[:review])
      flash[:notice] = "Review Updated"
      redirect_to_request_uri
    else
      render :edit
    end
  end

  def destroy
    @review = Review.find(params[:id])
    @review.destroy

    redirect_to_request_uri
  end
end
